package com.example.springboot.common;

import lombok.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result {
    public static final String CODE_SUCCESS = "200";
    public static final String CODE_AUTH_ERROR ="401";
    public static final String CODE_SYS_ERROR = "500";

    /**
     * 请求的返回编码 200 401没有权限 404没有资源 500系统错误，后台的问题
     * 编码可以表示这次请求是成功还是失败
     * 可以看到失败的类型是啥
     */

    private String code;
    private String msg;
    private Object data;

    public static Result success(){
        return new Result(CODE_SUCCESS, "请求成功",null);
    }
    public static Result success(Object data){
        return new Result(CODE_SUCCESS, "请求成功",data);
    }
    public static Result error(String msg){
        return new Result(CODE_SYS_ERROR, msg,null);
    }
    public static Result error(String code, String msg){
        return new Result(code, msg,null);
    }
    public static Result error(){
        return new Result(CODE_SYS_ERROR,"系统错误",null);
    }

}
